package com.hclc.yxb.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @Author:
 * 活动开启状态
 * @Date: Create in 4:22 下午 2020/8/9
 */
public enum TestEnum implements IEnum<Integer> {

    OPEN_TRUE(1, "开启"),


    OPEN_FALSE(0, "关闭"),

    ALL(2,"全部");

    @JsonValue
    @EnumValue
    private final int code;


    private final String desc;
    TestEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    @Override
    public Integer getValue() {
        return code;
    }
    public String getDesc(){return desc;}
    public static TestEnum find(String desc ) throws IllegalArgumentException{
        for (TestEnum model : TestEnum.values()) {
            if (model.getDesc().equals(desc)) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
    @JsonCreator
    public static TestEnum find(int code ) throws IllegalArgumentException{
        for (TestEnum model : TestEnum.values()) {
            if (model.getValue() == code) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
}
